/* ===================

AX2E (AXESCON XACML 2.0 Engine) is the Java authorization engine, which implements OASIS XACML 2.0 standard.
Copyright (C) 2007 AXESCON LLC

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA


Contact: AXESCON LLC - info{at}axescon.com

 =================== */
package axescon.xacml.api;

import axescon.xacml.model.policy.PolicyObject;

/**
 * @author argyn
 *         Date: Oct 13, 2005
 *         Time: 7:54:23 AM
 *         Responsibilities: base class for all XACML Exceptions
 */
public class XacmlException extends Exception {
    public XacmlException() {
        super();
    }

    public XacmlException(String s) {
        super(s);
    }

    public XacmlException(String s, int errCode) {
        super(s);
        setErrCode(errCode);
    }

    public XacmlException(String s, Throwable throwable) {
        super(s, throwable);
    }

    public XacmlException(String s, Throwable throwable, int errCode) {
        super(s, throwable);
        setErrCode(errCode);
    }

    public XacmlException(Throwable throwable) {
        super(throwable);
    }

    public XacmlException(Throwable throwable, int errCode) {
        super(throwable);
        setErrCode(errCode);
    }

    /**
     * AXESCON XACML error code
     */
    int errCode;

    /**
     * gets AXESCON XACML error code
     * @return AXESCON XACML error code
     */
    public int getErrCode() {
        return errCode;
    }

    /**
     * sets AXESCON XACML error code
     * @param errCode AXESCON XACML error code
     */
    public void setErrCode(int errCode) {
        this.errCode = errCode;
    }

    /**
     * everything's Ok, not an error code, really.
     */
    public static int ERR_CODE_OK = 0;

    /**
     * for general processing exceptions
     */
    public static int ERR_CODE_PROCESSING_GENERAL = 10000;
    /**
     * null id reference passed to resolve
     */
    public static int ERR_CODE_PROCESSING_NULL_ID_REFERENCE = 10001;
    /**
     * missing policy/set id not found in the store
     */
    public static int ERR_CODE_PROCESSING_ID_REFERENCE_NOT_FOUND = 10002;
    /**
     * missing policy/set id found in the store, but versions dont match
     */
    public static int ERR_CODE_PROCESSING_ID_REFERENCE_VERSION_MATCH = 10003;
    /**
     * null AttributeDesignator passed to Expression Evaluator
     */
    public static int ERR_CODE_PROCESSING_ATTRIBUTE_DESIGNATOR_NULL = 10004;
    /**
     * AttributeDesignator doesn't evaluate to Attribute
     */
    public static int ERR_CODE_PROCESSING_ATTRIBUTE_DESIGNATOR_EVALS_NO_ATTRIBUTE = 10005;
    /**
     * Found more than one matching policy for request
     */
    public static int ERR_CODE_PROCESSING_DUPLICATE_POLICY_REFERENCE = 10006;
    /**
     * Attribute Selector don't evaluate to Attribute
     */
    public static int ERR_CODE_PROCESSING_ATTRIBUTE_SELECTOR_EVAL_TO_NULL = 10007;

    /**
     * Factory cant load class
     */
    public static int ERR_CODE_CLASS_LOAD = 10008;

    /**
     * Factory cant instatiate class
     */
    public static int ERR_CODE_CLASS_INSTANTIATE = 10009;
    /**
     * Multiple matching policies
     */
    public static int ERR_CODE_PROCESSING_NO_MATCHING_POLICIES = 10010;

    /**
     * Function attribute types do not match specs
     */
    public static int ERR_CODE_PROCESSING_FN_WRONG_ARG_TYPE = 10011;

    /**
     * empty or wrong arg list passed to function
     */
    public static int ERR_CODE_PROCESSING_FN_WRONG_ARG_LIST = 10012;

    /**
     * Bag is found where singleargument was expected to function
     */
    public static int ERR_CODE_PROCESSING_FN_BAG_ARG = 10013;

    /**
     * Empty argument is sent to function
     */
    public static int ERR_CODE_PROCESSING_FN_EMPTY_ARG = 10014;

    /**
     * attempt to set wrong argument types to a function
     */
    public static int ERR_CODE_CONFIG_FN_WRONG_ARG_LIST = 10015;

    /**
     * Attempt to set a expression eval result to not AttributeValue or a bag of them
     */
    public static int ERR_CODE_PROCESSING_EXPR_BAD_EVAL_RESULT = 10016;

    /**
     * Attempt to get a bag from a expression eval result, which is singular
     */
    public static int ERR_CODE_PROCESSING_EXPR_NOT_BAG = 10017;

    /**
     * Attempt to get a singular value from a expression eval result, which is a bag
     */
    public static int ERR_CODE_PROCESSING_EXPR_NOT_SINGULAR= 10018;

    /**
     * Unsupported AttributeValue type requested
     */
    public static int ERR_CODE_PROCESSING_UNSUPPORTED_TYPE= 10019;

    /**
     * Function attribute types do not match specs
     */
    public static int ERR_CODE_PROCESSING_FN_URI_SYNTAX = 10020;

    /**
     * Unable to identify return type of attribute designator
     */
    public static int ERR_CODE_PROCESSING_UNKNOWN_RETURN_ATTRIBUTE_DESIGNATOR = 10021;

    /**
     * can't open reader for policy file
     */
    public static int ERR_CODE_CONFIG_POLICY_READER_IO = 10022;

    /**
     * for general syntax exceptions
     */
    public static int ERR_CODE_SYNTAX_GENERAL = 20000;
    /**
     * missing policy/set id in id reference object
     */
    public static int ERR_CODE_SYNTAX_MISSING_ID_REFERENCE = 20001;
    /**
     * condition evaluates to non boolean value
     */
    public static int ERR_CODE_SYNTAX_CONDITION_NON_BOOLEAN = 20002;
    /**
     * unsupported element in policy xml
     */
    public static int ERR_CODE_SYNTAX_UNSUPPORTED_POLICY_ELEMENT = 20003;
    /**
     * attribute designator found attribute values of different types
     */
    public static int ERR_CODE_SYNTAX_ATTR_DESIGNATOR_TYPE_MISMATCH = 20004;
    /**
     * unsupported combining algorithm
     */
    public static int ERR_CODE_SYNTAX_UNSUPPORTED_COMB_ALG = 20005;

    /**
     * reference to XACML policy object, where exception was thrown from
     */
    private PolicyObject policyObject;

    /**
     * get  reference to XACML policy object, where exception was thrown from
     * @return  reference to XACML policy object, where exception was thrown from
     */
    public PolicyObject getPolicyObject() {
        return policyObject;
    }

    /**
     * sets reference to XACML policy object, where exception was thrown from
     * @param policyObject  reference to XACML policy object, where exception was thrown from
     */
    public void setPolicyObject(PolicyObject policyObject) {
        this.policyObject = policyObject;
    }
}
